// highpassfilter.h

#ifndef HIGHPASSFILTER_H
#define HIGHPASSFILTER_H

#include "filter.h"

template<typename T>
class HighPassFilter : public Filter<T> {
public:
	HighPassFilter(float alpha)
		: alpha_((alpha > 0.0f && alpha < 1.0f) ? alpha : 1.0f)
		, initialized_(false)
		, value_(0)
		, prevInput_(0)
	{}

	virtual ~HighPassFilter() {}

	virtual T update(T input) {
		if (!initialized_) {
			prevInput_ = input;
			initialized_ = true;
		}
		
		value_ = static_cast<T>(alpha_ * (value_ + input - prevInput_));
		prevInput_ = input;
		return value_;
	}
	
	virtual T operator()() {
		return value_;
	}

	virtual void set(T value) {
		prevInput_ = value;
	}
	
	void setAlpha(float alpha) {
		alpha_ = alpha;
	}

private:
	HighPassFilter();

	float alpha_;
	bool initialized_;
	T value_;
	T prevInput_;
};


#endif
